

$(document).ready(function() {
	
});

function submitResult(){
	$('#submitResultForm').validate({
		 debug: debug,
	    rules: {
	    	inputDota2MatchID: {
		        minlength: 7,
		        maxlength:8,
		        required: true,
		        digits: true
		    },
		    checkWinLoseCheckboxHidden: {
		        minlength: 3,
		        maxlength:4,
		        required: true
		    }
	    },
	    highlight: function(label) {
	    	$(label).closest('.control-group').addClass('error');
	    },
	    success: function(label) {
	    	label
	    		.text('OK!').addClass('valid')
	    		.closest('.control-group').addClass('success');
	    }
	  });
	$("#matchSubmitresultButton").button();
	var matchID = getParameterByName("matchID");
	$('#myModalSubmitResult').modal('show');
	
	// Wenn Accept dann nächsten Modal aufmachen
	$("#myModalSubmitButton").click(function(){
			l("submitResult submit clicked", debug);
			if($('#submitResultForm').valid()){
				$("#matchSubmitresultButton").html("Result submitted").addClass("disabled").removeClass("btn-primary").removeAttr("onclick");
				var selection = $("#myModalSubmitResult div[data-toggle='buttons-radio']>button[class*='active']").val();
				l(selection, debug);
				$.ajax({
					url: 'ajax.php',
					type: "POST",
					dataType: 'json',
					data: {type:"match", mode: "submitResult", value:selection, ID:matchID},
					success: function(result) {
						$.cookie("matchFoundResultSubmitted", matchID, { expires: 1 });
						l("SubmitResult success", debug);
						$('#myModalSubmitResult').modal('hide');
						l("SubmitResult End", debug);
					}
				});
			}
	});
}



function setWinLoseValue(button){
	l(button, debug);
	var value = $(button).val();
	l(value, debug);
	$("#checkWinLoseCheckboxHidden").val(value);
}